//
//  LLT_ChangeNameViewController_LXH.m
//  CoderLLT
//
//  Created by lanou3g on 15/12/26.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "LLT_ChangeNameViewController_LXH.h"
#import <AVOSCloud/AVOSCloud.h>
#import "UIViewController+LLT_LoginAndRegist_LXM.h"
#import "UIViewController+LLT_UIViewControllerTools.h"
@interface LLT_ChangeNameViewController_LXH ()
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;

@end

@implementation LLT_ChangeNameViewController_LXH

#pragma mark --- dealloc
-(void)dealloc
{
    
}

#pragma mark --- 加载视图完毕

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.nameTextField.text = self.name;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark --- 实现返回和保存

- (IBAction)didClickReturnButton:(UIButton *)sender {
    DissMissBack;
}

- (IBAction)didClickSaveButton:(id)sender {
    [AVUser currentUser].username = self.nameTextField.text;
    [[AVUser currentUser] saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            [self showAlert:@"用户名修改成功" andAlertString:@"" andHandler:^(UIAlertAction *action) {
                self.block(self.nameTextField.text);
                DissMissBack;
            }];
        }else{
            [self showAlert:@"用户名修改失败" andAlertString:error.userInfo[@"error"] andHandler:^(UIAlertAction *action) {
                DissMissBack;
            }];
        }
    }];
   
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
